; 递归方式
(define (calcf n)
    (if (< n 3)
        n
        (+ (calcf (- n 1))
           (*   (calcf (- n 2)) 2)
           (*   (calcf (- n 3)) 3)
        )
    )
) 
(display (calcf 10))
(newline)

; 迭代方式
(define (calcf2 n)
        (calcf-iter 2 1 0 0 n)
)
(define (calcf-iter fn-1 fn-2 fn-3 counter maxcount)
    (if (< maxcount 3)
        maxcount    
        (if (> (+ counter 3) maxcount)
            fn-1
            (calcf-iter (+ fn-1 (* 2 fn-2) (* 3 fn-3))
                        fn-1
                        fn-2
                        (+ counter 1)
                        maxcount)
        )
    )    
)
(display (calcf2 10))
(exit)